<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资管苏宁开户信息列表</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<script type="text/javascript">
    var grid = null;

    // 资管机构id
    // var insIdList = ${insIdList};
    // console.log("资管机构id:" + insIdList);

    $(function () {
        //initOrgTree();
    });
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/institution/snbank/searchAssetManagerChangeCard.do',
            method : 'get',
            columns: [
                { display: '合同号', name: 'lsCntNo', Width: 140 , enabledSort:true},
                { display: '客户姓名', name: 'cstNm', width: 60, enabledSort:true},
                { display: '身份证号', name: 'certNo', minWidth: 150 , enabledSort:true},
                { display: '开户行', name: 'bkNm', width: 100 , enabledSort:true},
                { display: '银行账号', name: 'accNo', width: 100 , enabledSort:true},
                { display: '预留手机号', name: 'mp', width: 100 , enabledSort:true},
                { display: '第三方机构名称', name: 'fundRasInsNm', width: 100 , enabledSort:true},
                { display: '签约状态', name: 'signStatus', Width: 60, enabledSort:true,
                    render: function(rowdata, rowindex, value){
                        if (rowdata.insCode === 'tianjinbank' || rowdata.insCode === 'ylbank'){
                            if(rowdata.accResCd == '0000'){
                                return "已签约" ;
                            } else if (rowdata.accResCd == '9999'){
                                return "已解绑" ;
                            } else {
                                return "未签约" ;
                            }
                        } else if (rowdata.insCode === 'zgcbank'){
                            if(rowdata.accResCd === '1'){
                                return "已签约" ;
                            } else if (rowdata.accResCd === '0'){
                                return "已解绑" ;
                            } else {
                                return "未签约" ;
                            }
                        } else {
                            return rowdata.signStatus;
                        }
                    }
                },
                getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();
        //查询
        $("#searchBtn").click(function(event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            // console.log(data)
            data["crtTm"] = $("#crtTm").val();
            for (name in data){
                grid.setParm(name,data[name]);
            };
            grid.reload();
        });
        //清空
        $("#clearBtn").click(function(){
            $("#searchBar").ligerForm();
            var form = new liger.get("searchBar");
            //form.clear();
            form.setData({
                cstNm:" ",
                certNo:" ",
                insCode:" ",
            });
        })

    });

    function getGridOperColumnContent(){
        var data = {
            display: '操作',
            isSort: false,
            width: 180,
            align:'left',
            render: function (rowdata, rowindex, value){
                console.log(rowdata.verdictStatus);
                console.log(rowdata.insCode);
                var h="";
                var j="";
                var k = "";
                h+='<a class="sq-button-hasicon" style="color:blue;" href="javascript:checkSNPrjBscInfo(';
                h+="'"+rowdata.id+"',";
                h+="'"+rowdata.prjId+"',";
                h+="'"+rowdata.verdictStatus+"',";
                h+="'"+rowdata.accInfoId+"',";
                h+="'"+rowdata.insCode+"',";
                h+="'"+rowdata.fundRasInsNm+"'";
                h+=')">查看</a>';
                if("shnsbank" == rowdata.insCode || "tianjinbank" == rowdata.insCode || "zgcbank" == rowdata.insCode){

                    j+='<a class="sq-button-hasicon" style="color:blue;" href="javascript:unBindCard(';
                    j+="'"+rowdata.prjId+"',";
                    j+="'"+rowdata.insCode+"',";
                    j+="'"+rowdata.accInfoId+"',";
                    j+="'"+rowdata.fundRasInsNm+"'";
                    j+=')">解绑</a>';

                    k+='<a class="sq-button-hasicon" style="color:blue;" href="javascript:bindCard(';
                    k+="'"+rowdata.id+"',";
                    k+="'"+rowdata.prjId+"',";
                    k+="'"+rowdata.insCode+"',";
                    k+="'"+rowdata.accInfoId+"',";
                    k+="'"+rowdata.accResCd+"',";
                    k+="'"+rowdata.fundRasInsNm+"'";
                    k+=')">绑卡</a>';
                }else{

                    j+='<a class="sq-button-hasicon" style="color:blue;" href="javascript:exchangeCard(';
                    j+="'"+rowdata.id+"',";
                    j+="'"+rowdata.prjId+"'";
                    j+=')">换卡</a>';
                }


                return h + j + k;
            }

        }
        return data;
    }
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    var insCode = '${insCode}';//机构代码
    //查看
    function checkSNPrjBscInfo(id,prjId,verdictStatus,accInfoId,insCode,fundRasInsNm){
        if("shnsbank" == insCode){
            var queryBindFlag = true;
            $.ligerDialog.open({  title: '上海农商还款卡详情',height: 500,width: 850, url:'<%=path%>/institution/shnsbank/checkSHNSPrjBscInfo.do?prjId='+prjId+'&verdictStatus='+verdictStatus+'&queryBindFlag='+queryBindFlag});
        }else if ("tianjinbank" == insCode || "ylbank" == insCode || "zgcbank" == insCode){
            var _title = fundRasInsNm + '还款卡';
            $.ligerDialog.open({
                title: _title,
                height: 500,
                width: 850,
                //detailFlag ：1详情   2解绑    3绑卡
                url:'<%=path%>/institution/insChangeCrad/toCardDetial.do?prjId='+prjId+'&insCode='+insCode+'&accInfoId='+accInfoId+'&detailFlag='+'1',
            });
        } else{
            $.ligerDialog.open({  title: '苏宁还款卡',height: 500,width: 850, url:'<%=path%>/institution/snbank/checkSNPrjBscInfo.do?id='+id+'&prjId='+prjId+'&verdictStatus='+verdictStatus});
        }
    }
    //换卡
    function exchangeCard(id,prjId){
        $.ligerDialog.open({  title: '换卡',height: 500,width: 850, url:'<%=path%>/institution/snbank/exchangeCard.do?id='+id+'&prjId='+prjId});
    }

    //解绑
    function unBindCard(prjId,insCode,accInfoId,fundRasInsNm){
        //查询是否有银行卡号
        var wait_dialog;
        if (insCode == 'shnsbank'){
            $.ajax({
                type:"get",
                url: '<%=path%>/institution/shnsbank/queryUnBindCard.do?prjId='+prjId,
                dataType:"json",
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.open({  title: '上海农商还款卡解绑',height: 500,width: 850, url:'<%=path%>/institution/shnsbank/checkSHNSPrjBscInfo.do?prjId='+prjId});
                    } else {
                        // $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        } else if (insCode == 'tianjinbank' || insCode == 'zgcbank'){
            var _title = fundRasInsNm + '还款卡解绑';
            $.ligerDialog.open({
                title: _title,
                height: 500,
                width: 850,
                url:'<%=path%>/institution/insChangeCrad/toCardDetial.do?prjId='+prjId+'&insCode='+insCode+'&accInfoId='+accInfoId+'&detailFlag='+'2',
            });
        }

    }

    //绑卡
    function bindCard(id,prjId,insCode,accInfoId,accResCd,fundRasInsNm){
        if (insCode == 'shnsbank'){
            $.ligerDialog.open({  title: '绑卡',height: 500,width: 850, url:'<%=path%>/institution/shnsbank/bindCard.do?prjId='+prjId});
        } else if (insCode == 'tianjinbank' || insCode == 'zgcbank'){
            if ((insCode == 'tianjinbank' && accResCd == '0000') || (insCode == 'zgcbank' && accResCd == '1')){
                top.$.ligerDialog.SQalert({content: "已绑卡，请解绑后重新操作！", SQ_type: "error"});
                return false;
            }
            var _title = fundRasInsNm + '还款卡绑卡';
            $.ligerDialog.open({
                title: _title,
                height: 500,
                width: 850,
                url:'<%=path%>/institution/insChangeCrad/toCardDetial.do?prjId='+prjId+'&insCode='+insCode+'&accInfoId='+accInfoId+'&detailFlag='+'3',
            });
        }
    }

    function initOrgTree(){
        var params = {};
        params.cstMgrOrgCd = '${currOrg}';
        searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName:'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel : false
            }
        });
        $.ajax({
            type: 'get',
            dataType:'json',
            data: params,
            url: '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do',
            success:function(msg){
                if(msg.success == 1){
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('${currOrg}');
                }else{
                    UIUtils.alertErrorHold1(msg.info);
                }
            }
        });

    }
</script>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox" id="searchCstNmId">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox" id="searchCertNo">
                    <div class="label">身份证号</div>
                    <div class="field">
                        <input name="certNo" id="certNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox" id="searchFundRasInsCode" <sys:resourceAuth resCd="noThdOrg">style="display: none" </sys:resourceAuth>>
                    <div class="label">第三方机构</div>
                    <div class="field">
                        <select name="insCode"  id="insCode"  >
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${insCdList}" var="opt">
                                <option value="${opt.code}">${opt.codeNm}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn"  class="sq-button sq-button-round">清空</span>
                </div>
            </div>
        </form>
    </div>
</div>

<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>